




const oss = (url) => {
	if(typeof url === 'string') {
		if((/^(http|https):\/\/.+/.test(url))){
			return url 
		} else {
			if((/imageView2\/2/.test(url))){
				return 'https://369.juanjikeji.cn'+ url
			} else {
				return 'https://369.juanjikeji.cn'+ url
			}
		}
	} else if(url){
		let arr = []
		for(let i =0; i < url.length; i++ ){
			if((/^(http|https):\/\/.+/.test(url[i]))){
				arr.push(url[i]) 
			} else {
				if((/imageView2\/2/.test(url))){
					arr.push('http://qiniu.tangyuan.love/'+ url[i])
				} else {
					arr.push('http://qiniu.tangyuan.love/'+ url[i])
				}
				
			}
		}
		return arr
	} else {
		return url
	}
	
	
}
const back = () => {
	uni.navigateBack();
}

const authTo = (url) => {
	if(url[0] !== '/'){
		url = '/'+url
	}
	if(uni.getStorageSync('token')) {
		
		uni.navigateTo({
			url: url
		});
	} else {
		
		uni.navigateTo({
			url: '/pages/my/login/login'
		});
	}
	if(url[0] !== '/'){
		url = '/'+url
	}
	uni.navigateTo({
		url: url,
		fail(e) {
			
		}
	});
}
const goto = (url) => {
	
	if(url[0] !== '/'){
		url = '/'+url
	}
	uni.navigateTo({
		url: url,
		fail(e) {
			
		}
	});
}
const call =(num) =>{
	uni.makePhoneCall({
	    phoneNumber: num
	});
}
const copy = (content) => {
	uni.setClipboardData({
		data: content,
		success: function() {
			uni.$u.toast('复制成功')
		},
		fail: function() {
			uni.$u.toast('复制失败')
		}
	});
}
const toast = (word)=>{
	uni.$u.toast(word);
}

const utils = Vue => {
	Vue.prototype.$oss = oss
	Vue.prototype.$call = call
	Vue.prototype.$copy = copy
	Vue.prototype.$back = back
	Vue.prototype.$authTo = authTo
	Vue.prototype.$goto = goto
	Vue.prototype.$toast = toast
}


export default utils